package ru.inp.test.swt;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;

import javax.swing.JFrame;
import javax.swing.JPanel;

import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;

public class LineDrawer extends Thread {
	private GC gc;
	private ImageData imageData;

	public void setGC(GC gc) {
		this.gc = gc;
	}

	@Override
	public void run() {
		imageData = new ImageData(800, 600, 16, new PaletteData(0xFF, 0xFF00,
				0XFF0000));

		BufferedImage bi = new BufferedImage(800, 600,
				BufferedImage.TYPE_INT_RGB);
		int[] raster = ((DataBufferInt) bi.getRaster().getDataBuffer())
				.getData();

		Graphics2D g2d = bi.createGraphics();

		JFrame jFrame = new JFrame("FRAME");
		JPanel jPanel = new JPanel(new BorderLayout());

		jPanel.setDoubleBuffered(true);

		jFrame.getContentPane().add(jPanel);
		jFrame.getContentPane().setPreferredSize(new Dimension(800, 600));
		jFrame.pack();
		jFrame.setVisible(true);

		int index = 0xFF0000;

		for (int j = 0; j < 600; j++) {
			for (int i = 0; i < 800; i++) {
				raster[j * 800 + i] = index;
				// this.imageData.setPixel(i, j,index);
			}

			jPanel.getGraphics().drawImage(bi, 0, 0, null);
			// gc.drawImage(new Image(gc.getDevice(),imageData), 0, 0);
		}

		jFrame.dispose();

	}

}
